#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    ui->listWidget->addItem("C++");
    ui->listWidget->addItem("JAVA");
    ui->listWidget->addItem("GO");
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_pushButton_clicked()
{
    ui->listWidget->addItem(ui->lineEdit->text());
}




void Widget::on_pushButton_2_clicked()
{
    int row = ui->listWidget->currentRow();
    if(row < 0)
    {
        return;
    }
    ui->listWidget->takeItem(row);
}


void Widget::on_listWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
{
    if(current != nullptr)
    {
        qDebug() << "当前选中的是：" << current->text();
    }
    if(previous != nullptr)
    {
        qDebug() << "上次选中的是：" << previous->text();
    }
}

